package com.ruoyi.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.wx.domain.TGoods;
import com.ruoyi.wx.service.ITGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @Author: wind
 * @CreateTime: 2020-05-02
 * @Description: 商品
 */

@RestController
@RequestMapping("/api/goods")
public class ApiTgoodsController {

    @Autowired
    private ITGoodsService itGoodsService;


    /**
     * 获取所有商品
     * */
    @RequestMapping("/list")
    public AjaxResult goodsList(TGoods tGoods){
        Page<TGoods> goodsPage = new Page<>();
        goodsPage.setSize(tGoods.getPageSize());
        goodsPage.setCurrent(tGoods.getPageNum());
        return AjaxResult.success(itGoodsService.page(goodsPage));
    }

    /**
     * 获取商品明细
     */
    @RequestMapping("/detail")
    public AjaxResult goodsInfo(TGoods tGoods){
        return AjaxResult.success(itGoodsService.getById(tGoods.getGoodsId()));
    }
    /**
     * 搜索商品
     */
    @RequestMapping("/qsearch")
    public AjaxResult qsearch(TGoods tGoods){
        return AjaxResult.success(itGoodsService.list(new QueryWrapper<>(tGoods)));
    }
}
